package com.onemile.controls;

import java.util.ArrayList;
import java.util.List;

import com.onemile.app.R;
import com.onemile.entity.model.EAddress;

import android.R.integer;
import android.R.raw;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdpLV_Address extends BaseAdapter
{
   private ArrayList<EAddress> mList;
   private LayoutInflater mInflater;
   
   public AdpLV_Address(Context context,ArrayList<EAddress> _list)
   {
	  mList=_list;
	  mInflater=LayoutInflater.from(context);
   }
   
   @Override
   public int getCount()
   {
	  return mList.size();
   }

   @Override
   public Object getItem(int position)
   {
	  return mList.get(position);
   }

   @Override
   public long getItemId(int position)
   {
      return 0;
   }

   public void SetDefault(int position)
   {
	  for (int i=0;i<mList.size();i++)
	  {
		 EAddress address=mList.get(i);
		 address.setDefault(false);
		 if(i==position)
		 {
			address.setDefault(true);
		 }
		 mList.set(i, address);
	  }
	  notifyDataSetChanged();
   }
   
   public void RemoveAddress(int position)
   {
	  mList.remove(position);
	  notifyDataSetChanged();
   }
   
   @Override
   public View getView(int position, View convertView, ViewGroup parent)
   {
	 convertView=mInflater.inflate(R.layout.settlement_address_item, null);
	 TextView txtAddressName=(TextView)convertView.findViewById(R.id.txtAddressName_settleaddress_item);
	 TextView txtConsignee=(TextView)convertView.findViewById(R.id.txtConsignee_settleaddress_item);
	 TextView txtMobile=(TextView)convertView.findViewById(R.id.txtMobile_settleaddress_item);
	 TextView txtAddress=(TextView)convertView.findViewById(R.id.txtAddress_settleaddress_item);
	 TextView txtIsDefault=(TextView)convertView.findViewById(R.id.txtDefault_settleaddress_item);
	
	 txtAddressName.setText(mList.get(position).getAddressName());
	 txtMobile.setText(mList.get(position).getMobile());
	 txtAddress.setText(mList.get(position).getAddress());
	 txtConsignee.setText(mList.get(position).getConsignee());
	 
	 if(mList.get(position).IsDefault())
	 {
		txtIsDefault.setVisibility(View.VISIBLE);
	 }
	 else 
	 {
	   txtIsDefault.setVisibility(View.GONE); 
     }
	 
	 return convertView;
   }
}
